package com.cuit.controller;

import com.cuit.pojo.Doctor;
import com.cuit.pojo.DoctorOrder;
import com.cuit.service.D_OrderService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/doctor_cm/order/orderset")
public class d_OrderSitServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Doctor d2=(Doctor)request.getSession().getAttribute("doc");
        String[] day=request.getParameterValues("date");    //星期
        String[] time=request.getParameterValues("date2");
        int da[]=new int[day.length];   //星期

        String times[][]=(String[][]) request.getSession().getAttribute("times");;
        for(int i=0;i< day.length;i++){
            da[i]=Integer.parseInt(day[i]);
            if(request.getParameter("bo").equals("是")){
                for(int j=0;j<time.length;j++){
                    if("上午".equals(time[j])){
                        times[da[i]-1][0]="√";
                    }else if("下午".equals(time[j])){
                        times[da[i]-1][1]="√";
                    }else{
                        times[da[i]-1][2]="√";
                    }
                }
            }else{
                for(int j=0;j<time.length;j++){
                    if("上午".equals(time[j])){
                        times[da[i]-1][0]="";
                    }else if("下午".equals(time[j])){
                        times[da[i]-1][1]="";
                    }else{
                        times[da[i]-1][2]="";
                    }
                }
            }
        }
        DoctorOrder or=new DoctorOrder(d2.getId(),time,da);
        D_OrderService os=new D_OrderService(or);
        os.uptaS(request.getParameter("bo"));

        request.getSession().setAttribute("times",times);
        response.sendRedirect("/hospital/doctor_cm/order/d_order_set.jsp");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
